package vn.com.tiz.DocumentZ.test;

import vn.com.tiz.DocumentZ.R;
import vn.com.tiz.DocumentZ.view.ScrollViewEx;
import android.app.Activity;
import android.graphics.Color;
import android.media.JetPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.VideoView;

public class actTestVideoView extends Activity{

	VideoView video;
	LinearLayout container;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		createDynamicLayout();
		//loadStaticLayout();
		//JetPlayer
		
	}
	
	private void loadStaticLayout(){
		LinearLayout lnear = new LinearLayout(this);
		
		setContentView(R.layout.test_video);
		
		VideoView videoView = (VideoView)findViewById(R.id.videoView1);
		//videoView.setVideoPath("/mmt/sdcard/TheRoad.mp4");
		
		MediaController mediaController = new MediaController(this);
		//mediaplayer.setDataSource(String RTSP); 
		mediaController.setAnchorView(videoView);
		// Set video link (mp4 format )
		//Uri uri = Uri.parse("/mmt/sdcard/TheRoad.mp4");
		//videoView.setVideoPath("/mnt/sdcard/TheRoad.mp4");
		//videoView.setVideoPath("rtsp://sv02.kenhphimviet.com:1935/hoathinh/mp4:duoibongcay.mp4");
		//videoView.setd
		videoView.setVideoURI(Uri.parse("rtsp://v1.cache1.c.youtube.com/CjoLENy73wIaMQk2qVKPgzNShxMYESARFEIJbXYtZ29vZ2xlSARSCW15X3ZpZGVvc2CW95SO0YWooU8M/0/0/0/video.3gp"));
		videoView.setMediaController(mediaController);
		//videoView.setVideoURI(uri);
		videoView.start();
		//videoView.
		
	}
	
	private void createDynamicLayout(){
		
		ScrollViewEx mainView = new ScrollViewEx(this);
		mainView.setBackgroundColor(Color.GRAY);
		mainView.setOnScrolling(new ScrollViewEx.OnScrolling() {
			
			public void Scrolling() {
				// TODO Auto-generated method stub
				//video.refreshDrawableState();
				video.getHolder().setSizeFromLayout();
				container.requestLayout();
				container.invalidate();
				//video.requestLayout();
				//video.invalidate();
			}
		});
		
		container = new LinearLayout(this);
		container.setOrientation(LinearLayout.VERTICAL);
		
		video = new VideoView(this);
		LayoutParams lp = new LayoutParams(800,500);
		video.setLayoutParams(lp);
		
		//video.setVideoPath("/mnt/sdcard/TheRoad.mp4");
		//video.setVideoURI("rtsp://sv02.kenhphimviet.com:1935/hoathinh/mp4:duoibongcay.mp4");
		video.setVideoURI(Uri.parse("rtsp://sv02.kenhphimviet.com:1935/hoathinh/mp4:duoibongcay.mp4"));
		//video.setVideoURI(Uri.parse("rtsp://v1.cache1.c.youtube.com/CjoLENy73wIaMQk2qVKPgzNShxMYESARFEIJbXYtZ29vZ2xlSARSCW15X3ZpZGVvc2CW95SO0YWooU8M/0/0/0/video.3gp"));
		video.start();
		
		for(int i=0;i<10;i++){
			TextView txv = new TextView(this);
			txv.setText("Sample text");
			container.addView(txv);			
		}
		
		container.addView(video);
		
		for(int i=0;i<40;i++){
			
			TextView txv = new TextView(this);
			txv.setText("Sample text");
			container.addView(txv);
			
		}
		mainView.addView(container);
		setContentView(mainView);
		
	}
}
